#ifndef __FOC_TRANSFORM_H
#define __FOC_TRANSFORM_H

#include "at32f415_wk_config.h"
#include <math.h>
#include <stdint.h>
#include "MT6701.h"

#define PI 3.1416
#define sq3 1.73205080757f // 根号3

void SVPWM(float alpha, float beta, float *d);

typedef enum
{
    TRANFORM_INVERSE = 0, // 逆变换
    TRANFORM_FORWARD = 1  // 正变换
} tranform_driction_t;

uint8_t FOC_clark_transform(tranform_driction_t inverse, // 0: 逆变换 1: 正变换
                            float *a, float *b, float *c,
                            float *alpha, float *beta);

uint8_t FOC_park_transform(tranform_driction_t inverse, // 0: 逆变换 1: 正变换
                           float *theta, float *alpha, float *beta,
                           float *d, float *q);

void FOC_AngleInit(float angle);
uint8_t FOC_FullAngle(float *raw_angle, float *full_angle, float *v);
void FOC_elec_Angle(float *raw_angle_f, float *angle_e);

void FOC_Calibrate_Angle(void);
void FOC_angle(void);

#endif
